import axios from '@/utils/request.js'
import store from '@/store'
// import store from '@/store' // 把store 对象拿过来 相当于以前vue文件中的this.$store
// reqeust()调用传入请求的配置对象, 原地返回一个Promise对象
export * from './ArticleDetail'

// 用户 - 登录
export const loginAPI = ({ mobile, code }) => {
  return axios({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

// 用户 - 刷新token
export const refreshTokenAPI = () => axios({
  url: '/v1_0/authorizations',
  method: 'PUT',
  headers: {
    Authorization: `Bearer ${store.state.refresh_token}`
  }
})

// 用户 - 基本资料 我的页面使用
export const userInfoAPI = () => {
  return axios({
    url: '/v1_0/user'
  })
}

// 用户  - 个人资料 编辑资料使用
export const userProfileAPI = () => {
  return axios({
    url: '/v1_0/user/profile'
  })
}

// 用户 - 更新头像
export const updatePhotoAPI = (formData) => {
  return axios({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: formData
  })
}

// 用户 - 更新资料
export const updateProfileAPI = ({ birthday, name }) => {
  return axios({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: {
      birthday: birthday,
      name: name
    }
  })
}

// 频道  用户已选
export const channelListAPI = () => {
  return axios({
    url: '/v1_0/user/channels'
  })
}
// 口诀: 调用函数的地方需要结果, 就return
// 频道 - 获取所有
export const allChannelsAPI = () => {
  return axios({
    url: '/v1_0/channels'
  })
}

// 频道 - 更新已选
export const undateChannelAPI = ({ channels }) => {
  return axios({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channels
    }
  })
}

// 发布评论
export const UnshiftComment = ({ artId, commentText }) => {
  return axios({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target: artId,
      content: commentText
    }
  })
}

// 文章 - 评论取消点赞
export const commentDisLikeAPI = ({ commentId }) => {
  return axios({
    url: `/v1_0/comment/likings/${commentId}`,
    method: 'DELETE'
  })
}

// 搜索_联想菜单
export const suggestListAPI = ({ q }) => {
  return axios({
    url: '/v1_0/suggestion',
    params: {
      q: q
    }
  })
}
// 搜索 - 结果列表
export const searchResultAPI = ({ q, page }) => {
  return axios({
    url: '/v1_0/search',
    params: {
      q: q,
      page: page
    }
  })
}
